<?php

namespace Common\Model;

/**
 * Description of HotelChannelModel
 * @author songanwei
 * @date 2015-09-25 
 * @index hotelchannel(`hotelentity_id`, `status`)
 */
class HotelChannelModel extends BaseModel {

    protected $trueTableName = 'tb_hotel_channel';

    /**
     * 添加多条客栈分销渠道
     * @modify trainyao 2016-01-09  更改为添加多条
     * @param array $data 封装好的信息
     * @return boolean          执行结果
     */
    public function addInfo($data) {
        $result = $this->addAll($data);

        return empty($result) ? false : true;
    }

    /**
     * 获取分销渠道信息
     * @modify trainyao 2016-01-05  创建
     * @param   mixin   $channelIds 条目id(s)
     * @return array                信息数组
     */
    public function getInfo($channelIds) {
        $option = array();
        if(is_array($channelIds)) {
            $channelIds = implode(',', $channelIds);
        }

        $fields = 'id,hotelentity_id,name,type,status';
        $data = array();
        if(strpos($channelIds, ',') !== false) {
            $option['id'] = array('in', $channelIds);
            $data = $this->where($option)->field($fields)->select();
        } else {
            $option['id'] = $channelIds;
            $data = $this->where($option)->field($fields)->find();
        }

        return empty($data) ? array() : $data;
    }

    /**
     * 获取客栈所有分销渠道
     * @modify trainyao 2016-01-08 创建
     * @param  integer   $hotelId   客栈ID
     * @return array        信息数组
     */
    public function getInfoByHotel($hotelId) {
        $option = array(
            'hotelentity_id' => $hotelId,
            // 'status' => NOT_DELETE
        );
        $data = $this->where($option)->select();
        return empty($data) ? array() : $data;
    }

    /**
     * 删除条目
     * @modify trainyao 2016-01-08      创建
     * @param  integer   $hotelId        客栈id
     * @param  integer   $hotelChannelId 条目id
     * @return mixin                   删除结果
     */
    public function deleteInfo($hotelId, $hotelChannelId) {
        $option = array(
            'hotelentity_id' => $hotelId,
            'status' => NOT_DELETE,
            'id' => $hotelChannelId,
        );
        $data = array(
            'status' => IS_DELETE,
        );
        return $this->where($option)->save($data);
    }
}
